function ListNode(val) {
    this.val = val;
    this.next = null;
}
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var hasCycle = function(head) {
    // 边界条件
    if (head == null || head.next == null) return false
    // 定义快慢指针
    let fast = head
    let slow = head.next
    while (fast != slow) {
        if (fast == null || fast.next == null) {
            return false
        }
        fast = fast.next.next
        slow = slow.next
    }
    return true
};

let head = new ListNode(3)
let p1 = new ListNode(2)
let p2 = new ListNode(0)
let p3 = new ListNode(4)
head.next = p1;
p1.next = p2
p2.next = p3
p3.next = p1
console.log(hasCycle(head))
